home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / CDEF-DeBugger 2.0 ƒ / MyColor.c < prev    next >
Text File  |  1995-05-31  |  4KB  |  137 lines

  1. // this is a set of simple procedures I use often when I color
  2. // stuff. Nothing extremely difficult going on here. And I'm sure
  3. // there is a better way of doing things, but like I said before
  4. // I'm not the world's greatest programmer :)
  5.  
  6. // prototypes
  7. void     SetBackColor( short color );
  8. void     SetForeColor( short color );
  9. void    ColorNormal( void );
  10. short     GetDepth( CGrafPtr thePort );
  11. void    GetWinBackColor( WindowPtr theWindow, RGBColor *theColor );
  12. void    ConvertColor( short color, RGBColor *theColor );
  13. void    HiliteAndShadow( short hilite, short shadow, short var, Rect theRect );
  14.  
  15. /****************************************************************************
  16.  
  17.          Sets the fore color with specified color from "MyColors.h"
  18.          
  19. *****************************************************************************/
  20. void SetBackColor( short color )
  21. {
  22.     RGBColor    theColor;
  23.     
  24.     theColor.red = theColor.green = theColor.blue = color;
  25.     RGBBackColor( &theColor );
  26. }
  27.  
  28. /****************************************************************************
  29.  
  30.         Sets the fore color with specified color from "MyColors.h"
  31.  
  32. *****************************************************************************/
  33. void SetForeColor( short color )
  34. {
  35.     RGBColor    theColor;
  36.     
  37.     theColor.red = theColor.green = theColor.blue = color;
  38.     RGBForeColor( &theColor );
  39. }
  40.  
  41. /****************************************************************************
  42.  
  43.          Sets the Color back to black and white
  44.  
  45. *****************************************************************************/
  46. void ColorNormal( void )
  47. {
  48.     RGBColor    theColor;
  49.     
  50.     theColor.red = theColor.green = theColor.blue = BLACK_COLOR;
  51.     RGBForeColor( &theColor );
  52.     theColor.red = theColor.green = theColor.blue = WHITE_COLOR;
  53.     RGBBackColor( &theColor );
  54. }
  55.  
  56. /****************************************************************************
  57.  
  58.          Find the depth of the control's port.
  59.  
  60. *****************************************************************************/
  61. short GetDepth( CGrafPtr thePort )
  62. {
  63.     if ( (*thePort).portVersion == ((short)0xC000) ) {
  64.         return (**(*thePort).portPixMap).pixelSize;
  65.     } else {
  66.         return 1;
  67.     }
  68. }
  69.  
  70. /****************************************************************************
  71.  
  72.          Finds the content color of a given window
  73.  
  74. *****************************************************************************/
  75. void    GetWinBackColor( WindowPtr theWindow, RGBColor *theColor )
  76. {
  77.     AuxWinHandle    auxWinHan;
  78.         
  79.     if( GetAuxWin( theWindow, &auxWinHan ) ) {
  80.         // position 0 is the window's content color
  81.         *theColor = (**(**auxWinHan).awCTable).ctTable[0].rgb;
  82.     }
  83. }
  84.  
  85. /****************************************************************************
  86.  
  87.          Converts one of our predifened colors (MyColors.h) to a real RGBColor
  88.  
  89. *****************************************************************************/
  90. void    ConvertColor( short color, RGBColor *theColor )
  91. {
  92.     (*theColor).red = (*theColor).green = (*theColor).blue = color;
  93. }
  94.  
  95. /****************************************************************************
  96.  
  97.         Just a quick utility that will draw a hilite and shadow on
  98.         a given rectangle. The variable will indicate if you draw it
  99.         extruded in or out. 
  100.         
  101.         extrudeIn     = 0            // located in MyColors.h
  102.         extrudeOut    = 1
  103.         
  104. *****************************************************************************/
  105. void    HiliteAndShadow( short hilite, short shadow, short var, Rect theRect )
  106. {
  107.     InsetRect( &theRect, 1, 1 );
  108.     
  109.     if( var == extrudeOut ) {
  110.     
  111.         SetForeColor( hilite );
  112.         MoveTo( theRect.left + 1, theRect.bottom - 1 );
  113.         LineTo( theRect.right - 1, theRect.bottom - 1 );
  114.         LineTo( theRect.right - 1, theRect.top + 1 );
  115.         SetForeColor( shadow );
  116.         MoveTo( theRect.left, theRect.bottom - 2 );
  117.         LineTo( theRect.left, theRect.top );
  118.         LineTo( theRect.right - 2, theRect.top );
  119.     
  120.     } else {
  121.     
  122.         SetForeColor( shadow );
  123.         MoveTo( theRect.left + 1, theRect.bottom - 1 );
  124.         LineTo( theRect.right - 1, theRect.bottom - 1 );
  125.         LineTo( theRect.right - 1, theRect.top + 1 );
  126.         SetForeColor( hilite );
  127.         MoveTo( theRect.left, theRect.bottom - 2 );
  128.         LineTo( theRect.left, theRect.top );
  129.         LineTo( theRect.right - 2, theRect.top );
  130.         
  131.     }
  132.     
  133.     InsetRect( &theRect, -1, -1 );
  134.     ColorNormal();
  135. }
  136.  
  137.